#include<stdio.h>
#include<stdlib.h>
void ShellSort(int* a, int n)
{
	/*int gap = 2;

	for (int j = 0; j+gap < n; j ++)
	{
		int end = j;
		int tmp = a[end + gap];
		while (end >= 0)
		{
			if (tmp < a[end])
			{
				a[end + gap] = a[end];
				end-=gap;
			}

			else
			{
				break;
			}
		}
		a[end + gap] = tmp;
	}

for (int i = 0; i < n - 1; i++)
{
	int end = i;
	int tmp = a[end + 1];
	while (end >= 0)
	{
		if (tmp < a[end])
		{
			a[end + 1] = a[end];
			end--;
		}

		else
		{
			break;
		}

	}
	a[end + 1] = tmp;
}*/

	int gap = n;
	while (gap > 1)
	{
		gap /= 2;
		for (int i = 0; i + gap < n; i++)
		{
			int end = i;
			int tmp = a[end + gap];
			while (end >= 0)
			{
				if (tmp < a[end])
				{
					a[end + gap] = a[end];
					end -= gap;
				}

				else
				{
					break;
				}
			}
			a[end + gap] = tmp;
		}
	}
}

int main()
{
	int arr[] = { 23,51,5,7,82,1,2,4,6,431,3446,75,34,46,32,67,54,27,2,27,254,7435,16,547 };
	ShellSort(arr, sizeof(arr) / sizeof(arr[0]));
	for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); i++)
	{
		printf("%d ", arr[i]);
	}
	return 0;
}
